package com.pti.usermanager.web.controller;

import com.pti.usermanager.service.api.OrgService;
import com.pti.usermanager.web.dto.request.SaveOrgRequest;
import com.pti.usermanager.web.dto.request.UpdateOrgRequest;
import com.pti.usermanager.web.dto.response.ResultResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(value = "组织管理接口", tags = "提供组织的管理接口")
public class OrgController {
    private static final Logger logger = LogManager.getLogger(OrgController.class);
    @Autowired
    private OrgService orgService;

    @GetMapping("/org/getOrgTree/{usrId}/{compId}")
    @ApiOperation(value = "组织详情", notes = "组织详情", produces = "application/json")
    public ResultResponse findTreeByOrg(@PathVariable("usrId") Long usrId,@PathVariable("compId") Long compId) {
        return orgService.findTreeByOrg(usrId,compId);
    }

    @PostMapping("/org/saveOrg")
    @ApiOperation(value = "添加组织", notes = "添加组织", produces = "application/json")
    public ResultResponse saveOrg(@RequestBody SaveOrgRequest saveOrgRequest) {
        return orgService.saveOrg(saveOrgRequest);
    }

    @DeleteMapping("/org/delOrg/{orgId}")
    @ApiOperation(value = "删除组织", notes = "删除组织", produces = "application/json")
    public ResultResponse delOrg(@PathVariable("orgId") Long orgId) {
        return orgService.delOrg(orgId);
    }

    @PutMapping("/org/updateOrg")
    @ApiOperation(value = "修改组织", notes = "修改组织", produces = "application/json")
    public ResultResponse updateOrg(@RequestBody UpdateOrgRequest updateOrgRequest) {
        return orgService.updateOrg(updateOrgRequest);
    }

}
